package com.xingongchang.baolebei.activity;

import org.json.JSONException;
import org.json.JSONObject;

import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.external.androidquery.callback.AjaxStatus;
import com.insthub.BeeFramework.activity.BaseActivity;
import com.insthub.BeeFramework.model.BusinessResponse;
import com.insthub.BeeFramework.view.RoundImageView;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.xingongchang.baolebei.R;
import com.xingongchang.baolebei.model.ProtocolConst;
import com.xingongchang.baolebei.model.UserInfoModel;
import com.xingongchang.baolebei.protocol.USER_INFO;

public class Userprofile extends BaseActivity implements BusinessResponse {
	private RoundImageView viewimg;
	private TextView textView,textView2,textView3;
	private CheckBox box,gril;
	int sex;
	ImageLoader imageLoader = ImageLoader.getInstance();
	private UserInfoModel userInfoModel;
	private USER_INFO info;
	ImageView backButton;
	TextView title;
	private LinearLayout layout,layout2;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
    	super.onCreate(savedInstanceState);
    	setContentView(R.layout.profile_user);
    	intiview();
    	String uid=String.valueOf(getIntent().getIntExtra("userid",0));
    	userInfoModel=new UserInfoModel(this);
    	userInfoModel.addResponseListener(this);
    	userInfoModel.getTopicUserInfo(uid);
   }
	private void intiview() {
		viewimg=(RoundImageView) findViewById(R.id.userimgs); 
		textView=(TextView) findViewById(R.id.h_name);
		textView2=(TextView) findViewById(R.id.user_nick);
		textView3=(TextView) findViewById(R.id.useremail);
		box=(CheckBox) findViewById(R.id.boy_p);
		gril=(CheckBox) findViewById(R.id.girl_o);
		layout=(LinearLayout) findViewById(R.id.nan);
		layout2=(LinearLayout) findViewById(R.id.nv);
		backButton = (ImageView) findViewById(R.id.top_view_back);
		title = (TextView) findViewById(R.id.top_view_text);
		backButton.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View arg0) {
				finish();
			}
		});
		title.setText("个人资料");
	}
	@Override
	public void OnMessageResponse(String url, JSONObject jo, AjaxStatus status)
			throws JSONException {
			if (url.endsWith(ProtocolConst.USER_INFO)) {
				info = userInfoModel.userinfo;
				imageLoader.displayImage(info.user_photo,viewimg);
				textView.setText(info.nickname);
				textView2.setText(info.user_name);
				textView3.setText(info.email);
				sex = info.sex;
				if (sex == 1) {
					box.setVisibility(View.GONE);
					layout2.setVisibility(View.GONE);
	
				} else if (sex == 0) {
					layout.setVisibility(View.GONE);
					gril.setVisibility(View.GONE);
//					gril.setChecked(true);
				}
		}
	}
}
